package com.hyc.myvideo.data.adapter.my.recharge;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hyc.myvideo.R;
import com.hyc.myvideo.data.adapter.base.BaseListAdapter;
import com.hyc.myvideo.data.api.model.VipPackage;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * VIP会员套餐价格
 * @author gyb
 * @version 1.0
 * @created 2017/07/17
 */
public class PackageAdapter extends BaseListAdapter<VipPackage> implements View.OnClickListener {
    private int[] mIcon = {R.mipmap.icon_vip_month, R.mipmap.icon_vip_year, R.mipmap.icon_vip_founding};

    private Callback mCallback = null;
    public PackageAdapter(Context context, List<VipPackage> objects, Callback callback) {
        super(context, objects);
        this.mCallback = callback;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        VipPackage vip = mDataList.get(position);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_recharge_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
       if(vip != null){
           holder.imgCover.setImageResource(mIcon[position]);
           //购买天数
           String date = String.format(mContext.getString(R.string.huc_my_vip_day), vip.getVip_day());
           holder.textViewDate.setText(date);
           //购买金额
           String sun = String.format(mContext.getString(R.string.huc_my_vip_sun),new java.text.DecimalFormat("0.00").format(vip.getVip_rmb()));
           holder.textViewSun.setText(sun);
           //购买
           holder.buttonBuy.setOnClickListener(this);
           holder.buttonBuy.setTag(vip);
       }
        return convertView;
    }

    @Override
    public void onClick(View v) {
        mCallback.click(v);
    }


    public static class ViewHolder {
        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        //图标
        @BindView(R.id.img_everlasting)
        ImageView imgCover;
        //日期
        @BindView(R.id.t_date_id)
        TextView textViewDate;
        //金额
        @BindView(R.id.t_sun_id)
        TextView textViewSun;
        //购买
        @BindView(R.id.item_b_buy)
        Button buttonBuy;
    }

    //购买回调
    public interface Callback{
        public void click(View v);
    }

}
